#include <bits/stdc++.h>
using namespace std;
int T;
int n;
int a[200005] = {-1};
bool vis[200005];
int ans;
int C()
{
    int c_1, c_2;
    c_1 = c_2 = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (vis[i] == 0)
        {
            if (a[c_1] == a[i])
                ans += a[i];
            c_1 = i;
        }
        else
        {
            if (a[c_2] == a[i])
                ans += a[i];
            c_2 = i;
        }
    }
    return ans;
}
void dfs(int id)
{
    if (id == n + 1)
    {
        ans = max(ans,C());
        return;
    }
    dfs(id + 1);
    vis[id] = 1;
    dfs(id + 1);
    vis[id] = 0;
}
int main()
{
    freopen("colour.in", "r", stdin);
    freopen("colour.out", "w", stdout);
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            scanf("%d", a + i);
        ans = 0;
        dfs(1);
        printf("%d\n",ans);
    }
    return 0;
}
